package com.ipt.frm.pw;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import com.ipt.frm.bean.Mensaje;
import com.ipt.frm.enumeracion.TipoMensaje;

/**
 * Servlet implementation class LogoutServlet
 */
public class LogoutServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;

	/**
	 * @see HttpServlet#HttpServlet()
	 */
	public LogoutServlet() {
		super();
	}

	@Override
	public void service(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		boolean comprobar = (request.getHeader("user-agent").toLowerCase()
				.contains("mobile"));

		HttpSession session = request.getSession();

		session.invalidate();
		Mensaje msg = new Mensaje(TipoMensaje.INFO,
				"Agur, su sesion ha sido invalidada");
		request.setAttribute("MSG", msg);
		if (comprobar) {
			request.getRequestDispatcher("movil/login.jsp").forward(request,
					response);
		} else {
			request.getRequestDispatcher("login.jsp")
					.forward(request, response);
		}
	}
}
